package br.edu.unifei.cct720.trabalho06.gui.principal;

import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;

import br.edu.unifei.cct720.trabalho06.gui.componentes.JButtonAbrirArquivo;
import br.edu.unifei.cct720.trabalho06.gui.componentes.JButtonLimpar;
import br.edu.unifei.cct720.trabalho06.gui.componentes.JButtonPreencher;
import br.edu.unifei.cct720.trabalho06.gui.componentes.JButtonSair;
import br.edu.unifei.cct720.trabalho06.gui.componentes.JButtonSobre;
import br.edu.unifei.cct720.trabalho06.gui.painel.PainelDesenho;
import br.edu.unifei.cct720.trabalho06.controlador.principal.ControladorPrincipal;

/**
 * Classe responsavel por instanciar a interface principal
 * do projeto
 * 
 * @author fknappe
 */
public class JanelaPrincipal extends javax.swing.JFrame {

	// Declaracao das variaveis de instancia
	private ControladorPrincipal med;

	/**
	 * Construtor 
	 * 
	 * @param String title
	 */
	public JanelaPrincipal(String title) {
		super(title);
		this.med = new ControladorPrincipal(this);
		this.initComponents();
		this.med.registraEventos();
	}

	/**
	 * Metodo responsavel pela inicializacao e disposicao
	 * dos componentes na GUI
	 * 
	 * @return void
	 */
	public void initComponents() {
		java.awt.GridBagConstraints gridBagConstraints;

		// Inicializacao dos componentes
		panelMenu = new javax.swing.JPanel();
		panelDesenho = new PainelDesenho();
		btnAbrirArquivo = new JButtonAbrirArquivo("Abrir arquivo...", this.med);
		btnPreencher = new JButtonPreencher("Preencher poligono", this.med);
		btnLimpar = new JButtonLimpar("Remover Preenchimento", this.med);
		btnSobre = new JButtonSobre("Sobre...", this.med);
		btnSair = new JButtonSair("Sair...", this.med);
		panelMenu = new javax.swing.JPanel();
		
		// Definindo o content que sera utilizado na janela
		getContentPane().setLayout(new java.awt.GridBagLayout());
		
		panelDesenho.setBorder(BorderFactory.createTitledBorder(""));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.weighty = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelDesenho, gridBagConstraints);
		
		btnPreencher.setEnabled(false);
		btnLimpar.setEnabled(false);
		
		panelMenu.add(btnAbrirArquivo);
		panelMenu.add(btnPreencher);
		panelMenu.add(btnLimpar);
		panelMenu.add(btnSobre);
		panelMenu.add(btnSair);
		
		panelMenu.setBorder(BorderFactory.createTitledBorder(null, "Menu", TitledBorder.CENTER, TitledBorder.DEFAULT_POSITION));
		gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.weightx = 100.0;
		gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1);
		getContentPane().add(panelMenu, gridBagConstraints);
		
		this.setExtendedState(MAXIMIZED_BOTH);	
		this.setVisible(true);
	}

	// Declaracao dos componentes da GUI
	private javax.swing.JPanel panelMenu;
	private PainelDesenho panelDesenho;
	private JButtonAbrirArquivo btnAbrirArquivo;
	private JButtonSair btnSair;
	private JButtonSobre btnSobre;
	private JButtonPreencher btnPreencher;
	private JButtonLimpar btnLimpar;
	
	/**
	 * Metodo responsavel por habilitar as 
	 * acoes do menu apos carregamento da 
	 * forma geometrica do arquivo
	 * 
	 * @return void
	 */
	public void habilitarMenuPreenchimento() {
		this.getBtnPreencher().setEnabled(true);
		this.getBtnLimpar().setEnabled(false);
	}
	
	/**
	 * Metodo responsavel por desabilitar as
	 * acoes do menu apos a aplicacao do
	 * preenchimento sobre a forma geometrica
	 * 
	 * @return void
	 */
	public void desabilitarMenuPreenchimento() {
		this.getBtnPreencher().setEnabled(false);
		this.getBtnLimpar().setEnabled(true);
	}
	
	// Metodos getters e setters
	public PainelDesenho getPanelDesenho() {
		return panelDesenho;
	}
	
	public JButtonAbrirArquivo getBtnAbrirArquivo() {
		return btnAbrirArquivo;
	}

	public JButtonSair getBtnSair() {
		return btnSair;
	}

	public JButtonSobre getBtnSobre() {
		return btnSobre;
	}

	public JButtonPreencher getBtnPreencher() {
		return btnPreencher;
	}

	public JButtonLimpar getBtnLimpar() {
		return btnLimpar;
	}
}
